<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:i="http://www.springframework.org/schema/integration"
    xmlns:mail="http://www.springframework.org/schema/integration/mail"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:http="http://www.springframework.org/schema/integration/http"
    xsi:schemaLocation="http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd
        http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail-2.0.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <i:chain input-channel="bites" output-channel="mailChannel">
        <mail:header-enricher>
            <mail:from value="${mail.sender}" />
            <mail:to value="${mail.receiver}" />
            <mail:subject value="${mail.subject}" />
        </mail:header-enricher>
        <i:service-activator ref="mailMessageService" method="processMessage" />
    </i:chain>
    <bean id="mailMessageService" class="org.encuestame.core.integration.MailMessageService"/>
    <i:channel id="mailChannel" />
    <i:channel id="contentEnricher"/>

    <!--<mail:outbound-channel-adapter channel="plainMessage"
        mail-sender="mailSender" />
    -->

    <i:header-value-router input-channel="mailChannel" header-name="MESSAGE_TYPE">
        <i:mapping value="URL" channel="contentEnricher"/>
        <i:mapping value="TEXT" channel="responseChannel"/>
    </i:header-value-router>

    <http:outbound-gateway id="linkScrapping"
        url="{linkUrl}" request-channel="contentEnricher"
        reply-channel="responseChannel" http-method="GET"
        expected-response-type="java.lang.String">
        <http:uri-variable name="linkUrl" expression="payload" />
    </http:outbound-gateway>

    <i:channel id="responseChannel"/>

    <i:service-activator input-channel="responseChannel" ref="mailSenderActivator" method="sendMessage"/>

    <bean id="mailSenderActivator" class="org.encuestame.core.integration.MailSenderActivator">
        <property name="mailSender" ref="mailSender"/>
    </bean>



</beans>
